import {Injectable} from '@angular/core';
import {HttpClient} from '@angular/common/http';
import {Observable} from 'rxjs';
import {catchError} from 'rxjs/operators';
import {environment} from '../../../environments/environment';
import {BASE_HTTP_OPTIONS, baseHandleError, ReturnForm} from '@sb/base';

@Injectable({
    providedIn: 'root'
})
export class SystemService {

    private sysUrl = environment.baseServerUrl + 'main';

    constructor(private http: HttpClient) {
    }

    /**
     * 获取系统参数
     * @param paramCode 参数编码
     */
    getSysParam(paramCode: string): Observable<ReturnForm<string>> {
        return this.http.post<ReturnForm<string>>(`${this.sysUrl}/getTitle`, {
            paramCode: paramCode
        }, BASE_HTTP_OPTIONS).pipe(
            catchError(baseHandleError<ReturnForm<string>>('/getTitle'))
        );
    }
}
